package out_in_putStream;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class Inputstream {
    public static void main(String[] args) throws IOException {
        read_utf_8();
        read_gbk();
    }

    private static void read_gbk() throws IOException{
        FileInputStream fis = new FileInputStream("C:\\Users\\啦啦啦\\Desktop\\c.txt");
        InputStreamReader isr = new InputStreamReader(fis,"gbk");
        //指定使用utf-8格式的方法读取文件
        int len=0;
        char[] ch = new char[1024];
        while((len=isr.read(ch))!=-1)
        {
            System.out.println(new String(ch,0,len));
        }
    }

    private static void read_utf_8() throws IOException {
        FileInputStream fis = new FileInputStream("C:\\Users\\啦啦啦\\Desktop\\c.txt");
        InputStreamReader isr = new InputStreamReader(fis,"utf-8");
        //指定使用utf-8格式的方法读取文件
        int len=0;
        char[] ch = new char[1024];
        while((len=isr.read(ch))!=-1)
        {
            System.out.println(new String(ch,0,len));
        }
    }
}
